/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package condivisa;

import java.io.File;




import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import medico.BeanMedico;
import org.richfaces.event.UploadEvent;
import org.richfaces.model.UploadItem;

/**
 *
 * @author sestari
 */
public class BeanFormfoto {

    BeanMedico medico;

    public BeanFormfoto() {
        medico = ((BeanMedico) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("beanMedico"));
        setName(medico.getIdpaziente() + ".jpg");
    }

    public void listener(UploadEvent event) throws Exception {
        UploadItem item = event.getUploadItem();
        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
        String realpath = servletContext.getRealPath("/foto");
        File f = new File(realpath, getName());
        item.getFile().renameTo(f);
        

    }

    public long getTimeStamp() {
        return System.currentTimeMillis();
    }
    private String Name = "";

    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public String clearUploadData() {
        return "back";
    }
}